package com.leiduoduo.oms.service;

import com.leiduoduo.oms.dao.TableDao;
import com.leiduoduo.oms.pojo.Table;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class TableServiceImpl implements TableService {
    @Autowired
    TableDao tableDao;

    @Override
    public boolean addTable(Table table) {
        table.setCreated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()))
                .setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return tableDao.addTable(table);
    }

    @Override
    public boolean delTable(Table table) {
        table.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return tableDao.delTable(table);
    }

    @Override
    public boolean upTable(Table table) {
        table.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return tableDao.upTable(table);
    }

    @Override
    public Table getTableById(int id) {
        return tableDao.getTableById(id);
    }

    @Override
    public List<Table> getTableList() {
        return tableDao.getTableList();
    }

    @Override
    public boolean startDinner(Table table){
        table.setUpdated_at(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        return tableDao.startDinner(table);
    }
}
